GetUltrasonic
Reads the current value of the NXT ultrasonic sensor
Contents
Syntax
distance = GetUltrasonic(port)
distance = GetUltrasonic(port, handle)
Description
distance = GetUltraSonic(port) returns the current measurement value distance of the NXT ultrasonic sensor. distance represents the measured distance in cm. If no echo can be detected (which could indicate that either there is no obstacle in the way, or the ultrasound does not get reflected, e.g. by fur-like surfaces), the reading will be 255. If no measurement can be made (defect sensor, cable disconnected, etc.), a value of -1 will be returned.
The given port number specifies the connection port. The value port can be addressed by the symbolic constants SENSOR_1 , SENSOR_2, SENSOR_3 and SENSOR_4 analog to the labeling on the NXT Brick.
The last optional argument can be a valid NXT handle. If none is specified, the default handle will be used (call COM_SetDefaultNXT to set one).
Note:
This function only works when the sensor was correctly opened with OpenUltrasonic(port). If the sensor is being used in snapshot mode, GetUltrasonic will not work correctly!
For different uses, see also OpenUltrasonic(port, 'snapshot') and the functions USMakeSnapshot and USGetSnapshotResults.
Example
OpenUltrasonic(SENSOR_4); distance = GetUltrasonic(SENSOR_4); CloseSensor(SENSOR_4);
See also
OpenUltrasonic, USMakeSnapshot, USGetSnapshotResults, CloseSensor, NXT_LSRead, NXT_LSWrite
Signature
- Author: Linus Atorf, Alexander Behrens (see AUTHORS)
- Date: 2008/01/15
- Copyright: 2007-2008, RWTH Aachen University